<template>
  <a-form-model :model="form" ref="ruleForm" :label-col="labelCol"
    :wrapper-col="wrapperCol">
	<a-form-model-item
	  label="上传技术手册"
	>
	<a-upload
	    action="https://admin.lhlzgroup.com/api/upload/img"
	    :file-list="fileList"
		 @change="handleChange"
	  >
	    <a-button> <a-icon type="upload" /> Upload </a-button>
	  </a-upload>
	</a-form-model-item>
  </a-form-model>
</template>

<script>
import {uploadImg} from '@/api/upload.js'	
import {serveFileCreat,serveFileList} from '@/api/serve.js'	

function getBase64(file) {
  return new Promise((resolve, reject) => {
    const reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onload = () => resolve(reader.result);
    reader.onerror = error => reject(error);
  });
}
const fields = ['title', 'startAt', 'owner', 'description']

export default {
  name: 'addserve',
  props: {
    id: {
      type: Number,
      default: null
    }
  },
  data () {
    return {
     labelCol: { span: 4 },
     wrapperCol: { span: 14 },
	  previewImage: '',
	  fileList:[],
	  form:{}
    }
  },
  mounted () {
	  this.getList()
  },
  methods: {
	  // 获取列表
	  getList(){
	  		serveFileList({id:this.id}).then(res=>{
	  			if(res.data.list.length>0){
	  				this.fileList = res.data.list.map(item=>{
	  					return {
						   uid: item.id,
						   name: item.name,
						   status: 'done',
						   url: this.vuex_src+item.url,
						   response:{
							   url:item.url
						   }
						 }
	  				})
	  			}
	  		})  
	  },
	 handleChange({ fileList }) {
	   this.fileList = fileList;
	 },
	 upload(e){
		let formData=new FormData();
		formData.append('file',e.file)
		uploadImg(formData).then(res=>{
		})
	 },
    onOk () {
		console.log(this.fileList)
		let arr = this.fileList.map(item=>{
			return [item.name,item.response.url,this.id]
		})
		 // 创建
		 return new Promise(resolve => {
			serveFileCreat({fileList:arr}).then(res=>{
			  resolve(true)
			})
		 })
    },
  }
}
</script>
